import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:hitutor/UI/Home/Home.dart';
import 'package:hitutor/Util/Global.dart';
import 'package:hitutor/Util/HttpGo.dart';
import 'package:hitutor/Util/MyColor.dart';
import 'package:hitutor/Util/PageUtil.dart';
import 'package:hitutor/Widget/MyButton.dart';
import 'package:hitutor/Widget/MyDialog.dart';

class DialogReadNotice extends StatelessWidget {
  dynamic data;
  Function() readCallback;

  DialogReadNotice(this.data, {required this.readCallback});

  @override
  Widget build(BuildContext context) {
    readNotice() {
      HttpGo(context).post("/Information/ReadAnnouncement", {"announcementId": data["announcementId"]}, (data) {
        Home.homeKey.currentState?.getHomePage(false);
        readCallback();
        PageUtil().back(context);
      }, (code, error) => showToast(error));
    }

    return Container(
        decoration: Global.getWhiteBg(8),
        padding: EdgeInsets.all(16),
        child: Column(mainAxisSize: MainAxisSize.min, children: [
          Text("${data["title"]}", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Color(0xff2e4f90))),
          Container(
              constraints: BoxConstraints(maxHeight: 400),
              padding: EdgeInsets.fromLTRB(0, 16, 0, 16),
              child: SingleChildScrollView(child: HtmlWidget("${data["content"]}")
                  // style: TextStyle(fontSize: 14, color: Color(0xff333333), fontWeight: FontWeight.bold)
                  )),
          Visibility(
              visible: data["confirmDateTime"] == null,
              child: Button("已閱讀", width: 100, height: 28, bgColor: MyColor.BlueHome, radius: 4, onTap: readNotice))
        ]));
  }
}
